﻿package view.component
{
    import com.core.*;
    import com.greensock.*;
    import com.sh.game.display.*;
    import com.sh.game.global.*;
    import com.sh.game.util.*;
    import flash.display.*;
    import flash.geom.*;
    import flash.utils.*;
    import manager.*;
    import morn.core.handlers.*;
    import view.message.*;

    public class Temptation extends Sprite
    {
        private var cell:TemptationCell;
        private var isSet:Boolean = false;
        private var showDic:Dictionary;
        private var maxCount:int = 0;
        private var timeLine:TimelineLite;
        private var fsOffset:int = 0;
        private var sp:Sprite;

        public function Temptation()
        {
            this.showDic = new Dictionary();
            this.sp = new Sprite();
            this.addChild(this.sp);
            UIVisibleManager.instance.register("temptation", this.sp, "up");
            return;
        }// end function

        public function initSet() : void
        {
            var _loc_1:Object = null;
            var _loc_2:Object = null;
            var _loc_3:Object = null;
            var _loc_4:Object = null;
            if (!this.isSet)
            {
                _loc_1 = ModelProxy.getValue("data", "temptationInfo");
                if (_loc_1)
                {
                    _loc_2 = UserData.getUserData();
                    if (_loc_2)
                    {
                        _loc_3 = ConfigDictionary.data.temptation;
                        for each (_loc_4 in _loc_3)
                        {
                            
                            if (_loc_4.career > 0)
                            {
                                if (_loc_4.career != _loc_2.career)
                                {
                                    continue;
                                }
                            }
                            if (_loc_4.sex < 2)
                            {
                                if (_loc_4.sex != _loc_2.sex)
                                {
                                    continue;
                                }
                            }
                            this.showDic[_loc_4.type] = _loc_4;
                            var _loc_7:String = this;
                            var _loc_8:* = this.maxCount + 1;
                            _loc_7.maxCount = _loc_8;
                        }
                        this.isSet = true;
                        this.update();
                    }
                }
            }
            return;
        }// end function

        public function update() : void
        {
            var _loc_1:Point = null;
            var _loc_2:Object = null;
            var _loc_3:int = 0;
            var _loc_4:String = null;
            var _loc_5:Object = null;
            var _loc_6:Object = null;
            var _loc_7:Boolean = false;
            var _loc_8:int = 0;
            var _loc_9:XMLMovieClip = null;
            var _loc_10:int = 0;
            var _loc_11:XMLMovieClip = null;
            if (!ModelProxy.getValue("data", "fashenIsInit"))
            {
                return;
            }
            if (!this.isSet)
            {
                this.initSet();
            }
            else
            {
                _loc_2 = ModelProxy.getValue("data", "temptationInfo");
                _loc_3 = _loc_2.items.length + 1;
                for (_loc_4 in this.showDic)
                {
                    
                    _loc_6 = this.showDic[_loc_4];
                    if (_loc_6.itemid)
                    {
                        _loc_7 = false;
                        for each (_loc_8 in _loc_2.items)
                        {
                            
                            if (_loc_6.itemid == _loc_8)
                            {
                                _loc_7 = true;
                                break;
                            }
                        }
                        if (!_loc_7)
                        {
                            if (int(_loc_4) < _loc_3)
                            {
                                _loc_3 = int(_loc_4);
                            }
                            break;
                        }
                    }
                }
                this.checkFaShen();
                if (_loc_3 >= 5)
                {
                    _loc_3 = _loc_3 + this.fsOffset;
                }
                if (_loc_3 > this.maxCount)
                {
                    if (this.cell)
                    {
                        if (this.cell.data.type >= 5)
                        {
                            this.doDispose();
                            return;
                        }
                        _loc_1 = UIGlobel.pointsDic["bag"];
                        _loc_9 = new XMLMovieClip(this.cell._IconMc._clsurl, this.cell._IconMc._xml);
                        GlobalLayer.instance.root.stage.addChild(_loc_9);
                        _loc_9.x = this.x + this.cell._IconMc.x;
                        _loc_9.y = this.cell._IconMc.y;
                        TweenLite.to(_loc_9, 3, {x:_loc_1.x - 15, y:_loc_1.y, scaleX:0.5, scaleY:0.5, onComplete:this.doremove, onCompleteParams:[_loc_9]});
                        TweenLite.to(this.cell, 0.2, {alpha:0, onComplete:this.doDispose});
                    }
                    return;
                }
                _loc_5 = this.showDic[_loc_3];
                if (this.cell)
                {
                    if (this.cell.data.type == _loc_5.type)
                    {
                        return;
                    }
                }
                if (_loc_5.openlv > 0)
                {
                    _loc_10 = UserData.getUserData("level");
                    if (_loc_10 < _loc_5.openlv)
                    {
                        return;
                    }
                }
                if (this.cell == null)
                {
                    this.cell = new TemptationCell();
                    this.sp.addChild(this.cell);
                    this.cell.show(_loc_5);
                }
                else
                {
                    this.cell.removeEvent();
                    _loc_1 = UIGlobel.pointsDic["bag"];
                    if (this.cell.data.type >= 5)
                    {
                        this.tweenComp(_loc_3);
                        return;
                    }
                    _loc_11 = new XMLMovieClip(this.cell._IconMc._clsurl, this.cell._IconMc._xml);
                    GlobalLayer.instance.root.stage.addChild(_loc_11);
                    _loc_11.x = this.x + this.cell._IconMc.x;
                    _loc_11.y = this.cell._IconMc.y;
                    TweenLite.to(_loc_11, 3, {x:_loc_1.x - 15, y:_loc_1.y, scaleX:0.5, scaleY:0.5, onComplete:this.doremove, onCompleteParams:[_loc_11]});
                    TweenLite.to(this.cell, 0.2, {alpha:0, onComplete:this.tweenComp, onCompleteParams:[_loc_3]});
                }
            }
            return;
        }// end function

        public function checkFaShen() : void
        {
            var _loc_6:Object = null;
            var _loc_7:Object = null;
            var _loc_1:* = ModelProxy.getValue("data", "fashenjihuostate");
            var _loc_2:* = ConfigDictionary.data.hero;
            var _loc_3:Boolean = false;
            var _loc_4:Boolean = false;
            var _loc_5:Boolean = false;
            for each (_loc_6 in _loc_1)
            {
                
                _loc_7 = _loc_2[_loc_6.heroid + "_" + _loc_6.level];
                switch(int(_loc_7.id))
                {
                    case 2:
                    {
                        _loc_3 = true;
                        break;
                    }
                    case 3:
                    {
                        _loc_4 = true;
                        break;
                    }
                    case 4:
                    {
                        _loc_5 = true;
                        break;
                    }
                    default:
                    {
                        break;
                    }
                }
            }
            this.fsOffset = 0;
            if (_loc_3)
            {
                var _loc_8:String = this;
                var _loc_9:* = this.fsOffset + 1;
                _loc_8.fsOffset = _loc_9;
                if (_loc_4)
                {
                    var _loc_8:String = this;
                    var _loc_9:* = this.fsOffset + 1;
                    _loc_8.fsOffset = _loc_9;
                    if (_loc_5)
                    {
                        var _loc_8:String = this;
                        var _loc_9:* = this.fsOffset + 1;
                        _loc_8.fsOffset = _loc_9;
                    }
                }
            }
            return;
        }// end function

        public function doremove(param1:XMLMovieClip) : void
        {
            GlobalLayer.instance.root.stage.removeChild(param1);
            param1.dispose(true);
            return;
        }// end function

        public function doDispose() : void
        {
            this.cell.parent.removeChild(this.cell);
            this.cell.filters = [];
            this.cell.dispose();
            this.cell = null;
            ModelProxy.change("tips", "state", "close");
            return;
        }// end function

        public function tweenComp(param1:int) : void
        {
            this.cell.show(this.showDic[param1], new Handler(this.showAnimate));
            this.cell.alpha = 1;
            this.cell.scaleX = 0;
            this.cell.scaleY = 0;
            return;
        }// end function

        public function showAnimate() : void
        {
            if (this.cell == null)
            {
                if (Config.debug)
                {
                    Alert2.show("不要惊讶，如果出现说明这是内部测试，测试号：9001显示异常，请确认当前干了什么！", "测试异常错误", ["确定"]);
                }
                return;
            }
            this.cell.parent.removeChild(this.cell);
            this.sp.addChild(this.cell);
            this.cell.x = this.cell.registerPoi.x;
            this.cell.y = this.cell.registerPoi.y;
            this.cell.removeEvent();
            if (this.timeLine)
            {
                this.timeLine.kill();
                this.timeLine = null;
            }
            this.timeLine = new TimelineLite();
            this.timeLine.append(new TweenLite(this.cell, 1, {scaleX:1, scaleY:1, rotation:1080}));
            this.timeLine.append(new TweenMax(this.cell, 0.5, {glowFilter:{color:16763904, alpha:1, blurX:50, blurY:50}}));
            this.timeLine.append(new TweenMax(this.cell, 0.5, {glowFilter:{color:16763904, alpha:0, blurX:50, blurY:50}}));
            this.timeLine.append(new TweenLite(this.cell, 0.1, {x:this.cell.registerPoi.x, y:this.cell.registerPoi.y, onComplete:this.onComplete}));
            return;
        }// end function

        public function onComplete() : void
        {
            this.timeLine.kill();
            this.timeLine = null;
            if (this.cell)
            {
                this.cell.filters = [];
                this.cell.initEvent();
            }
            return;
        }// end function

        public function updateLevel() : void
        {
            var _loc_1:int = 0;
            var _loc_2:Object = null;
            var _loc_3:int = 0;
            var _loc_4:Object = null;
            if (this.isSet)
            {
                _loc_2 = ModelProxy.getValue("data", "temptationInfo");
                _loc_3 = _loc_2.items.length + 1;
                if (_loc_3 >= 5)
                {
                    return;
                }
                if (_loc_3 <= this.maxCount)
                {
                    _loc_4 = this.showDic[_loc_3];
                    if (_loc_4.openlv > 0)
                    {
                        _loc_1 = UserData.getUserData("level");
                        if (_loc_1 < _loc_4.openlv)
                        {
                            return;
                        }
                    }
                    if (this.cell == null)
                    {
                        this.cell = new TemptationCell();
                        this.sp.addChild(this.cell);
                        this.cell.show(this.showDic[_loc_3], new Handler(this.showAnimate));
                        this.cell.scaleX = 0;
                        this.cell.scaleY = 0;
                    }
                    else
                    {
                        _loc_1 = UserData.getUserData("level");
                        this.cell.changeState(_loc_1 >= _loc_4.level);
                    }
                }
            }
            return;
        }// end function

        public function checkFashen() : void
        {
            if (this.cell)
            {
                if (this.cell.data.type > 4)
                {
                    this.cell.checkFashenState();
                }
            }
            return;
        }// end function

        public function fashenChange() : void
        {
            if (this.isSet)
            {
                if (this.cell)
                {
                    if (this.cell.data.type > 4)
                    {
                        this.update();
                    }
                }
            }
            return;
        }// end function

    }
}
